<template>
  <div class="sshzrc">
    <div class="query">
      <div>
        <!-- <span>管理单位：</span> -->
        <!-- <el-cascader
          size="small"
          @change="org_change"
          :options="jigou_1"
          :props="{
            label: 'Name',
            value: 'Id',
            children: 'Children',
            checkStrictly: true,
          }"
          clearable
        ></el-cascader> -->
        <!-- <span style="display: inline-block; margin-left: 8px">责任医生：</span>
        <el-input
          size="small"
          v-model="query.doctorName"
          style="width: 200px"
        ></el-input> -->
        <!-- <span style="display: inline-block; margin-left: 8px">查询时间：</span>
        <el-date-picker
          v-model="query.time"
          size="small"
          @change="time_change"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
        <el-button size="small" @click="get_list" style="margin-left: 10px"
          >查询</el-button
        > -->
        <!-- <el-button size="small">刷新</el-button> -->
      </div>
      <div style="margin: 10px 0" v-if="false">
        <span>人员状态：</span>
        <el-select v-model="query.status" placeholder="请选择" size="small">
          <el-option label="正常" value="0"> </el-option>
          <el-option label="失访" value="2"> </el-option>
          <el-option label="死亡" value="3"> </el-option>
        </el-select>
        <span style="display: inline-block; margin-left: 8px">签约状态：</span>
        <el-select v-model="query.signStatus" placeholder="请选择" size="small">
          <el-option label="全部" value="-1"> </el-option>
          <el-option label="在签" value="1"> </el-option>
          <el-option label="未签" value="0"> </el-option>
        </el-select>
        <span style="display: inline-block; margin-left: 8px">性别：</span>
        <el-select v-model="query.gender" placeholder="请选择" size="small">
          <el-option label="全部" value="-1"> </el-option>
          <el-option label="男" value="1"> </el-option>
          <el-option label="女" value="2"> </el-option>
        </el-select>
        <span style="display: inline-block; margin-left: 8px">年龄段：</span>
        <el-select v-model="query.ageType" placeholder="请选择" size="small">
          <el-option label="全部" value="-1"> </el-option>
          <el-option label="35岁以下" value="0"> </el-option>
          <el-option label="35-45岁" value="1"> </el-option>
          <el-option label="46-55岁" value="2"> </el-option>
          <el-option label="56-65岁" value="3"> </el-option>
          <el-option label="65岁以上" value="4"> </el-option>
        </el-select>
        <span style="display: inline-block; margin-left: 8px">健康体检：</span>
        <el-select v-model="query.bodyCheck" placeholder="请选择" size="small">
          <el-option label="全部" value="-1"> </el-option>
          <el-option label="已检" value="1"> </el-option>
          <el-option label="未检" value="0"> </el-option>
        </el-select>
      </div>
      <div v-if="false">
        <span>姓名：</span>
        <el-input
          size="small"
          v-model="query.name"
          style="width: 200px"
        ></el-input>
        <span style="display: inline-block; margin-left: 8px">身份证号：</span>
        <el-input
          size="small"
          v-model="query.idCard"
          style="width: 200px"
        ></el-input>
      </div>
    </div>
    <div class="main">
      <el-table
        :data="tableData"
        v-loading="isLoading"
        border
        style="width: 100%"
        height="700"
        :header-cell-style="{
          color: '#000',
          backgroundColor: 'rgb(157,201,210)',
          fontFamily: 'FangSong',
        }"
        :span-method="objectSpanMethod"
      >
        <el-table-column align="center" label="科室" prop="name">
        </el-table-column>
        <el-table-column align="center" label="医生" prop="user_name">
        </el-table-column>
        <el-table-column align="center" label="候诊">
          <el-table-column align="center" label="小程序" prop="小程序待诊">
          </el-table-column>
          <el-table-column align="center" label="自助机" prop="自助机待诊">
          </el-table-column>
          <el-table-column align="center" label="窗口" prop="窗口待诊">
          </el-table-column>
          <el-table-column align="center" label="总人数" prop="待诊">
          </el-table-column>
        </el-table-column>
        <el-table-column align="center" label="已诊">
          <el-table-column align="center" label="小程序" prop="小程序已诊">
          </el-table-column>
          <el-table-column align="center" label="自助机" prop="自助机已诊">
          </el-table-column>
          <el-table-column align="center" label="窗口" prop="窗口已诊">
          </el-table-column>
          <el-table-column align="center" label="总人数" prop="已诊">
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <div class="page" v-if="false">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="[15, 20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      query: {
        orgId: 0,
        status: "0",
        signStatus: "-1",
        gender: "-1",
        ageType: "-1",
        bodyCheck: "-1",
        name: "",
        idCard: "",
      },
      page: {
        currentPage: 1,
        pageSize: 15,
        total: 1,
      },
      tableData: [],
      option_1: [],
      option_2: [],
      option_3: [],
      option: {},
      isLoading: false,
      jigou_1: [],
      nameSpanArr: [],
      pos: 0,
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$get("/Data/OutpatientDynamicManagement?orgId=3168").then((res) => {
        this.tableData = res.Data;
        this.getSpanArr(this.tableData, "name");
      });
    },

    org_change(val) {
      this.query.orgId = val[val.length - 1];
    },
    get_list() {
      var data = {
        currentPage: this.page.currentPage,
        pageSize: this.page.pageSize,
        filter: this.query,
      };
      this.isLoading = true;
      this.$post(baseUrl.mbIp + "/api/Data/GetGluStandingBook", data)
        .then((res) => {
          this.isLoading = false;
          if (res.StatusCode != 200) {
            this.$notify.error({
              title: "错误",
              message: res.Errors,
            });
          }
          this.tableData = res.Data.PageList;
          this.page.total = res.Data.Total;
        })
        .catch((err) => {
          this.isLoading = false;
        });
    },
    time_change() {
      this.query.startTime = this.query.time[0];
      this.query.endTime = this.query.time[1];
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.get_list();
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.get_list();
    },
    getSpanArr(data, prop) {
      // 清空之前的合并信息
      this.nameSpanArr = [];
      this.pos = 0;
      for (let i = 0; i < data.length; i++) {
        if (i === 0) {
          // 第一行默认合并行数为 1
          this.nameSpanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前行的 prop 字段值是否与上一行相同
          if (data[i][prop] === data[i - 1][prop]) {
            // 相同则合并行数加 1
            this.nameSpanArr[this.pos] += 1;
            this.nameSpanArr.push(0);
          } else {
            // 不同则合并行数为 1
            this.nameSpanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        // 第一列（索引为 0）应用合并规则
        const _row = this.nameSpanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
  },
};
</script>

<style scoped lang="scss">
.sshzrc {
  background-color: #fff;
  height: calc(100vh - 46px);
  padding: 15px;
  .main {
    margin-top: 10px;
  }

  .page {
    text-align: right;
    margin-top: 15px;
  }
}
</style>